<?php

	include('addons/shared/init.php');
	
	if ( md_IsOutputMDC() )
	{
		header("Content-Transfer-Encoding: binary"); 
	}
	
	if ( $md_db == 0 )
	{
		mdc_SendError('This is a Maxsi Distribution Content Server without a MySQL database.');
		die();
	}
	
	$md_Addons_Slot		=	md_sql('SELECT foldername FROM '.md_GetDatabaseName('addons').' WHERE enabled = 1 ORDER BY priority DESC');
		
	$md_Addons			=	array();
	$md_AddonsNum		=	$md_sql_total[$md_Addons_Slot];
	
	for ( $I = 0; $I < $md_AddonsNum; $I++)
	{
		$md_Addons[$I]	=	$md_sql_row[$md_Addons_Slot]['foldername'];
		md_sql_next($md_Addons_Slot	);
	}
	
	md_clearslot($md_Addons_Slot);
	
	$md_FoundAction		=	false;
	$md_FoundErrorPage	=	false;
	
	for ($I = 0; $I < $md_AddonsNum && !$md_FoundAction; $I++)
	{
		if ( !$md_FoundAction && file_exists('addons/'.$md_Addons[$I].'/action.php') )
		{
			include('addons/'.$md_Addons[$I].'/action.php');
		}
	}
	
	for ($I = 0; $I < $md_AddonsNum && !$md_FoundAction; $I++)
	{
		if ( file_exists('addons/'.$md_Addons[$I].'/nosuchaction.php') )
		{
			include('addons/'.$md_Addons[$I].'/nosuchaction.php');
			$md_FoundErrorPage	=	true;
		}
	}
	
	if ( !$md_FoundAction && !$md_FoundErrorPage )
	{	
		if ( isset($_GET['action']) )
		{
			mdc_SendError('Maxsi Distribution Error: Action "'.$_GET['action'].'" is not supported by this content server.');
		}
		else
		{
			mdc_SendInfo('This is a Maxsi Distribution Content Server with no public front page.');
		}
	}
?>